/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package hibernateexample;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author tboyuktas
 */
public class HibernateExample {

    public HibernateExample() {
        
        Session session = null;
        try {
        
            session = HibernateUtil.getSessionFactory().openSession();
            session.beginTransaction();

            Query query = session.createQuery("select a from AddBook a where a.book_id < 3 ");            

            Object list = query.list();
            
            List<AddBook> books = (List<AddBook>) list;
            
            for (AddBook book : books) {
                System.out.println(book.getBook_id() + " " + book.getBook_type());
            }
            
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if(session != null) {
                session.flush();
                session.close();
            }
        }
    }

    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        new HibernateExample();
        
    }
    
}
